# server.py
from flask import Flask, Response
import time

from flask_cors import CORS

app = Flask(__name__)
CORS(app, resources={r"/*": {"origins": "http://localhost:3000"}})

def generate_messages():
    """Generator function to yield messages."""
    count=1
    while True:
        yield f"data: The current time is {time.ctime()}\n\n"
        count+=1
        time.sleep(1)  # Send a message every second
        if count > 10:
            break

@app.route('/stream')
def stream():
    """Route to stream SSE messages."""
    return Response(generate_messages(), mimetype='text/event-stream')

if __name__ == '__main__':
    app.run(debug=True, threaded=True)
